package com.other.src.main.java.com.kuang.pc;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

public class TestA {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        test1();  15744
//        test2(); 16426
//        test3(); 1053
    }

    public static void test3(){
        long start = System.currentTimeMillis();


//        Future

        // 麻志涛 涛哥
        // stream 并行流
        long sum = LongStream.rangeClosed(0L, 10_0000_0000L).parallel().reduce(0, Long::sum);
        long end = System.currentTimeMillis();
        System.out.println("sum = "+sum+"时间："+(end-start));
    }

    public static void test2() throws ExecutionException, InterruptedException {

        long start = System.currentTimeMillis();



        ForkJoinPool forkJoinPool = new ForkJoinPool();



        ForkJoinTask<Long> a = new
                A(0L,10_0000_0000L);

        ForkJoinTask<Long> submit = forkJoinPool.submit(a);
        Long sum = submit.get();



        long end = System.currentTimeMillis();
        System.out.println("sum = "+sum+"时间："+(end-start));
    }

    public static void test1(){
        Long sum = 0L;
        long start = System.currentTimeMillis();
        for (Long i = 0L; i < 10_0000_0000; i++) {
            sum += i;
        }

        long end = System.currentTimeMillis();
        System.out.println("sum = "+"时间："+(end-start));
    }
}
